package org.example;

import org.example.Model.User;
import org.example.config.RPCConfig;
import org.example.proxy.MockServiceProxy;
import org.example.proxy.UserServiceFactory;
import org.example.service.UserService;
import org.example.utils.ConfigUtils;

public class Consumer {
    public static void main(String[] args) {
        RPCConfig rpcConfig = ConfigUtils.loadConfig(RPCConfig.class, "rpc");
        System.out.println("rpcConfig = " + rpcConfig);
//        UserService userService = new UserServiceProxy();
        // 正常调用远程服务
        UserService userService = UserServiceFactory.getUserService(UserService.class);

        // 检测Mock是否调用
        if(RPCApplication.getConfig().isMock()) {
            // 通过Mock模拟调用远程服务
//        UserService userService = UserServiceFactory.getMockProxy(UserService.class);
            System.out.println("通过Mock模拟调用远程服务:" + userService.getNumber());
        }

        User user = new User();
        user.setName("John");
        // 调用远程服务
        User result = userService.getUser(user);
        if(result!= null) {
            System.out.println("远程服务调用成功 " +result.getName());
        } else {
            System.out.println("远程服务调用失败 user = null");
        }
    }
}